 <template>
  <div class="index-box" ref="index">
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <div class="moneyTotal" ref="topData">
            <div class="item">
              <div class="money">{{topData.totalOrderTurnover}}</div>
              <div class="text">订单成交总计(单)</div>
            </div>
            <div class="item">
              <div class="money">{{topData.totalOrderAmount}}</div>
              <div class="text">订单总金额(元)</div>
            </div>
            <div class="item">
              <div class="money">{{topData.totalActuallyPaid}}</div>
              <div class="text">实付总计(元)</div>
            </div>
            <div class="item">
              <div class="money">{{topData.totalReceipts}}</div>
              <div class="text">实收总计(元)</div>
            </div>
            <div class="item">
              <div class="money">{{topData.totalPoints}}</div>
              <div class="text">总积分(积分)</div>
            </div>
        </div>
        <div class="search" ref="search">
          <el-form :inline="true" :model="searchForm" size="small" ref="searchForm" @submit.native.prevent
            class="demo-form-inline" id="searchBox">
            <el-form-item prop="buyTelephone">
                <el-input v-model="searchForm.buyTelephone" clearable placeholder="购买人手机号"></el-input>
            </el-form-item>
            <el-form-item prop="orderNo">
                <el-input v-model="searchForm.orderNo" clearable placeholder="订单编号"></el-input>
            </el-form-item>
            <el-form-item prop="orderType">
                <el-select
                  v-model="searchForm.orderType"
                  placeholder="订单类型"
                  clearable
                  size="small"
                >
                  <el-option label="好礼" value="1"></el-option>
                  <el-option label="扫码" value="3"></el-option>
                  <el-option label="好店" value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="paymentTime">
               <el-date-picker v-model="paymentTime" type="daterange" align="right" unlink-panels range-separator="至"
                 start-placeholder="付款开始日期" end-placeholder="付款结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                 :picker-options="pickerOptions">
               </el-date-picker>
            </el-form-item>
            <el-form-item prop="completeTime">
               <el-date-picker v-model="completeTime" type="daterange" align="right" unlink-panels range-separator="至"
                 start-placeholder="完成开始日期" end-placeholder="完成结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                 :picker-options="pickerOptions">
               </el-date-picker>
            </el-form-item>

            <el-form-item class="clearfix">
              <el-button type="primary" @click="handleSearch()" icon="el-icon-search">搜索</el-button>
              <el-button icon="el-icon-refresh" size="small" @click="resetSearch">重置</el-button>

            </el-form-item>
            <div class="actionBtnRight" style="margin-left:auto">

            </div>
          </el-form>
        </div>
        <div class="actionBtn" ref="actionBtn">
          <div class="actionBtnLeft">
            <el-radio-group v-model="searchForm.pointsLevelId" size="small" @change="handleSearch()" >
              <el-radio-button label="">全部</el-radio-button>
              <el-radio-button :label="item.id" v-for="item in pointsLevelList">{{item.name}}</el-radio-button>
            </el-radio-group>
            <el-button
              style="margin-left:10px"
              type="warning"
              icon="el-icon-download"
              size="small"
              :loading="btnLoading"
              @click="handleExport"
            >导出</el-button>
          </div>
          <div class="actionBtnRight">
              <MyRefresh></MyRefresh>
              <MyTableColumnSet :tableColumn.sync="tableColumn" :hideTableColumn.sync="hideTableColumn" :tableColumnType.sync="tableColumnType"></MyTableColumnSet>
          </div>
        </div>
        <div class="table" ref="table">
          <el-table :data="dataList" style="width: 100%;" :height="tableHeight" v-loading='loading'  stripe border>
            <el-table-column label="序号" type="index" width="50" align="center" v-if="!hideTableColumn.includes('index')"></el-table-column>
            <el-table-column prop="buyTelephone" label="购买人手机号" v-if="!hideTableColumn.includes('buyTelephone')" align="center"></el-table-column>
            <el-table-column prop="orderNo" label="订单编号" v-if="!hideTableColumn.includes('orderNo')" align="center"></el-table-column>
            <el-table-column prop="orderTypeName" label="订单类型" v-if="!hideTableColumn.includes('orderTypeName')" align="center"></el-table-column>
            <el-table-column prop="goodsNum" label="商品数量(件)" v-if="!hideTableColumn.includes('goodsNum')" align="center" width="80"></el-table-column>
            <el-table-column prop="orderTotal" label="订单合计金额(元)" v-if="!hideTableColumn.includes('orderTotal')" align="center"></el-table-column>
            <el-table-column prop="actuallyAmount" label="实付合计金额(元)" v-if="!hideTableColumn.includes('actuallyAmount')" align="center"></el-table-column>
            <el-table-column prop="receiptsAmount" label="实收合计金额(元)" v-if="!hideTableColumn.includes('receiptsAmount')" align="center"></el-table-column>
            <el-table-column prop="givePoints" label="赠送积分(积分)" v-if="!hideTableColumn.includes('givePoints')" align="center"></el-table-column>
            <el-table-column prop="paymentDate" label="付款日期" v-if="!hideTableColumn.includes('paymentDate')" align="center"></el-table-column>
            <el-table-column prop="completeDate" label="完成日期" v-if="!hideTableColumn.includes('completeDate')" align="center"></el-table-column>
            <el-table-column prop="name" label="操作" width="110" align="center" fixed="right">
              <template #default="scope">
                  <el-button
                    size="medium"
                    type="text"
                    icon="el-icon-tickets"
                    @click="handleDetail(scope.row)"
                  >订单详情</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="page" ref="page">
          <MyPagination
            :total="total"
            :page.sync="searchForm.pageNum"
            :limit.sync="searchForm.pageSize"
            @pagination="dataInfo"
          />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import common from '@/api/api';
  import {
    pointsGetUserOrderQueryRes,
    pointsUser0rderItemExport,
    pointsUserOrderItemList
  } from '@/api/getData'
  import option from '../../common/option.js';

  export default {
    data() {
      return {
        loading: false,
        btnLoading:false,
        paymentTime:[],
        completeTime:[],
        searchForm: {
          buyTelephone:'',
          orderNo:'',
          orderType:'',
          pointsLevelId:'',
          pageNum: 1,
          pageSize: 20,
        },
        tableColumn:[{/*自定义表格列*/
            name:'序号',
            value:'index'
        },{
            name:'购买人手机号',
            value:'buyTelephone'
        },{
            name:'订单编号',
            value:'orderNo'
        },{
            name:'订单类型',
            value:'orderTypeName'
        },{
            name:'商品数量(件)',
            value:'goodsNum'
        },{
            name:'订单合计金额(元)',
            value:'orderTotal'
        },{
            name:'实付合计金额(元)',
            value:'actuallyAmount'
        },{
            name:'实收合计金额(元)',
            value:'receiptsAmount'
        },{
            name:'赠送积分(积分)',
            value:'givePoints'
        },{
            name:'付款日期',
            value:'paymentDate'
        },{
            name:'完成日期',
            value:'completeDate'
        }],
        hideTableColumn:[],/*自定义表格列需要隐藏的*/
        tableColumnType:'staffManagement',/*自定义表格列类型传参*/
        tableHeight:0,//table 高度
        dataList:[],
        total: 0,
        topData:{},
        pointsLevelList:[]
      }
    },
    created() {

    },
    computed:{
      pickerOptions: () => {
        return option.pickerOptions;
      }
    },
    mounted() {
      // this.getCategoryDetails({categoryKey:'points_level_config'}).then(res=>{ this.pointsLevelList = res.data; });
      // this.getTopDataFN();
      // this.dataInfo();
      this.$nextTick(() => {
          this.tableHeight = this.$refs.index.offsetHeight - this.$refs.topData.offsetHeight  - this.$refs.search.offsetHeight- this.$refs.actionBtn.offsetHeight - this.$refs.page.offsetHeight - 75;
      })
    },
    methods: {
      /** 导出按钮操作 */
       handleExport() {
        let data = this.addDateRange(this.searchForm, this.paymentTime, 'paymentStartDate', 'paymentEndDate');
        data = this.addDateRange(this.searchForm, this.completeTime, 'completeStartDate', 'completeEndDate');
         this.$modal.confirm('是否确认导出搜索数据项？').then(() => {
           this.btnLoading = true;
           return pointsUser0rderItemExport(data);
         }).then(response => {
           this.$download.name(response.msg);
           this.btnLoading = false;
         }).catch(() => {});
      },
      handleDetail(row){
        this.$router.push({path:'/order/orderDetail',query:{id:row.orderId}});
      },
      getTopDataFN(){
        let data = this.addDateRange(this.searchForm, this.paymentTime, 'paymentStartDate', 'paymentEndDate');
        data = this.addDateRange(this.searchForm, this.completeTime, 'completeStartDate', 'completeEndDate');
        pointsGetUserOrderQueryRes(data).then((res)=>{
          this.topData = res.data;
        })

      },
      resetSearch(){
        this.paymentTime = [];
        this.completeTime = [];
        this.searchForm.pageNum = 1;
        this.resetForm('searchForm');
         this.getTopDataFN();
        this.dataInfo();
      },
      handleSearch(){
          this.searchForm.pageNum = 1;
          this.getTopDataFN();
          this.dataInfo();
      },
      async dataInfo() {
        try {
          let data = this.addDateRange(this.searchForm, this.paymentTime, 'paymentStartDate', 'paymentEndDate');
          data = this.addDateRange(this.searchForm, this.completeTime, 'completeStartDate', 'completeEndDate');
          this.loading = true;
          const result = await pointsUserOrderItemList(data);
          if (result.code == 200) {
            this.total = result.total;
            this.dataList = result.rows;
          } else {
            this.$message.error(result.msg);
          }
          this.loading = false;
        } catch (err) {
          this.loading = false;
          console.log(err)
        }
      },

    }
  }
</script>

<style scoped lang="scss">

  .el-table .el-dropdown-link{
      cursor: pointer;
      color: #61997A;
      margin-left: 5px;
  }
    .leftDialog{
      height:540px;
      overflow-y: auto;
    }
    .activeVerticalBox .activeItem{
      color:#61997A;
      cursor: pointer;
      margin: 0px;
      text-align: center;
      height:20px;
      line-height: 20px;
    }
    .activeVerticalBox .el-dropdown{
      display: flex;
      justify-content: center;
      color:#61997A;
      cursor: pointer;
    }
    .activeCheckedBox{
      border-top: 1px solid #ddd;
      padding:10px;
      height:52px;
      .el-tag{
        margin-right:10px;
      }
    }
    .rateBox /deep/ .el-rate__icon{
      margin-right: 0px;
    }
    .rateBox>p{
      margin: 0px;
    }
    .rateBox>p> /deep/ .el-rate{
      height:25px;
      line-height:25px;
      display:flex;
    }
    .rateBox>p> /deep/ .el-rate .el-rate__item{
      display:flex;
      align-items: center;
    }
    .rateBox .rateText{
      width:60px;
    }
    .rateBox .content{
      display: flex;
    }
    .rateBox .el-tooltip{
      width: 100px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      display: inline-block;
    }
</style>
